package org.apache.database.helper;

import org.apache.database.dao.Condition;
import org.apache.database.enums.DeleteActionEnum;
import org.apache.database.utils.AnnotationUtil;

import java.io.Serializable;

public class DeleteHelper extends BaseHelper {



    public int deleteByCondition(Class<?> cls, Condition condition) {
        String tabName = getTabName(cls);
        String s = DeleteActionEnum.BASE.init().withTableName(tabName).deleteByCondition(condition);

        return  getSqlExecute().execute(s);
    }
    public int deleteIds(Class<?> tabClass, Serializable... ids) {
        String primaryKey = AnnotationUtil.getPrimaryKey(tabClass);

        Condition condition = new Condition.Builder()
                .in(primaryKey,ids)
                .builder();

        return deleteByCondition(tabClass,condition);
    }
}